﻿/*
Author :    Lion(刘祖民)
QQ     :    10318975
Blog   :    http://www.cnblogs.com/tearsFish/
Version：   Beta 1.5
*/


//PageCreater Begin

//配置验证
function InitValidator() {
    var isSuccess = true;
    var arr = new Array();
    var i = 0;
    $("select,input", "#divContent").each(function () {
        var flag = true;
        var aaa = $(this).attr("id");
        if ($(this).attr("reg") != undefined) {
            if (!validate($(this))) {
                flag = false;
            }
        }
        arr[i] = flag;
        i++;
    });
    for (var j = 0; j < arr.length; j++) {
        if (arr[j] == false) {
            alert("验证失败，请查看页面提示！");
            isSuccess = false;
            break;
        }
    }
    return isSuccess;
}

//获取URL参数方法
function getUrlPara() {
    var url = location.href;
    var result = "";
    for (var i = url.length - 1; i > 0; i--) {
        if (url[i] != "/") {
            result += url[i];
        }
        if (url[i] == "/") {
            break;
        }
    }
    result = result.split("").reverse().join("");
    return result;
}

//创建首页
function CreateIndexPage(dataUrl, strColumn, strOpreate) {
    $.ajaxSetup({ cache: false });
    urlGetData = dataUrl;
    InitData(strColumn);
    InitOpreate(strOpreate);
    GridTitleSettiong();
    BindData(1, 15, "", "", "", "");
}
//创建新建页
function CreatePageFram(str) {
    InitData(str);
    $("#divContent").append("<table id='tabContent'></table>");
    for (var i = 0; i < columnNames.length - 1; i++) {
        var colID = columnNames[i].split(",")[0];
        var colVal = columnNames[i].split(",")[1];
        var inputType = columnNames[i].split(",")[2];
        var validate = columnNames[i].split(",")[3];
        if (inputType.split('|')[0] == "text") {
            if (inputType.split('|')[1] == "date") {
                if (validate == "notnull") {
                    $("#tabContent").append("<tr><td>" + colVal + "</td><td><input type='text' id='" + colID + "' Name='" + colID + "' reg='^.+$' tip='" + colVal + "不能为空' onclick='WdatePicker()' /><td><tr>");
                }
            }
            else {
                if (validate == "notnull") {
                    $("#tabContent").append("<tr><td>" + colVal + "</td><td><input type='text' id='" + colID + "' Name='" + colID + "' reg='^.+$' tip='" + colVal + "不能为空' /><td><tr>");
                }
            }
        } else if (inputType.split('|')[0] == "password") {
            if (validate == "notnull") {
                $("#tabContent").append("<tr><td>" + colVal + "</td><td><input type='password' id='" + colID + "' Name='" + colID + "' reg='^.+$' tip='" + colVal + "不能为空' /><td><tr>");
            }
        } else if (inputType.split('|')[0] == "select") {
            if (validate == "notnull") {
                var tempstr = "<tr><td>" + colVal + "</td><td><select id='" + colID + "' name='" + colID + "' reg='[^0]' tip='请选择一个！'><option value=''>－－－请选择－－－</option>";
                for (var j = 1; j < inputType.split('|').length; j++) {
                    tempstr += "<option value='" + inputType.split('|')[j].split('!')[1] + "'>" + inputType.split('|')[j].split('!')[0] + "</option>";
                }
                $("#tabContent").append("<tr><td>" + tempstr + "<td><tr>");
            }
        }
    }
    ValidateInte();
}
//创建带值的修改页
function CreatePageFramWithValue(str, url) {
    $.ajaxSetup({ cache: false });
    InitData(str);
    $.getJSON(url, { id: getUrlPara() }, function (json) {
        $("#divContent").append("<table id='tabContent'></table>");
        for (var i = 0; i < columnNames.length - 1; i++) {
            var colID = columnNames[i].split(",")[0];
            var colVal = columnNames[i].split(",")[1];
            var inputType = columnNames[i].split(",")[2];
            var validate = columnNames[i].split(",")[3];
            if (inputType.split('|')[0] == "text" && inputType.split('|')[1] != "date") {
                if (validate == "notnull") {
                    $("#tabContent").append("<tr><td>" + colVal + "</td><td><input type='text' id='" + colID + "' Name='" + colID + "' reg='^.+$' tip='" + colVal + "不能为空' value='" + json[colID] + "' /><td><tr>");
                }
            } else if (inputType.split('|')[0] == "password") {
                if (validate == "notnull") {
                    $("#tabContent").append("<tr><td>" + colVal + "</td><td><input type='password' id='" + colID + "' Name='" + colID + "' reg='^.+$' tip='" + colVal + "不能为空' value='" + json[colID] + "' /><td><tr>");
                }
            } else if (inputType.split('|')[0] == "text" && inputType.split('|')[1] == "date") {
                if (validate == "notnull") {
                    $("#tabContent").append("<tr><td>" + colVal + "</td><td><input type='text' id='" + colID + "' Name='" + colID + "' reg='^.+$' tip='" + colVal + "不能为空' value='" + json[colID] + "' onclick='WdatePicker()' /><td><tr>");
                }
            }  
            else if (inputType.split('|')[0] == "select") {
                if (validate == "notnull") {
                    var tempstr = "<tr><td>" + colVal + "</td><td><select id='" + colID + "' name='" + colID + "' reg='[^0]' tip='请选择一个！'><option value=''>－－－请选择－－－</option>";
                    for (var j = 1; j < inputType.split('|').length; j++) {
                        var tmpVal = json[colID].toLocaleLowerCase();
                        if ((tmpVal == inputType.split('|')[j].split('!')[1]) || (tmpVal == inputType.split('|')[j].split('!')[0])) {
                            tempstr += "<option selected='selected' value='" + inputType.split('|')[j].split('!')[1] + "'>" + inputType.split('|')[j].split('!')[0] + "</option>";
                        } else {
                            tempstr += "<option value='" + inputType.split('|')[j].split('!')[1] + "'>" + inputType.split('|')[j].split('!')[0] + "</option>";
                        }
                    }
                    $("#tabContent").append("<tr><td>" + tempstr + "<td><tr>");
                }
            }
        }
        ValidateInte();
    });
}
//获取数据连接
var urlGetData = "";
//删除链接
var urlDelete = "";
//操作集合
var opreate = new Array();
//定义列名
var columnNames = new Array();
//定义可排序的列名
var sortcolumnNames = new Array();
//定义Grid标题配置
var sortDeatail = new Array();
//定义默认排序方式
var sortType = "asc";
//定义默认起始页码
var pageNum = 1;
//定义页码数量
var pageCount = 1;
//定义默认排序属性
var tmpPropoty;
//定义显示条数
var tmpSize = 0;

//表头细节设置
function GridTitleSettiong() {
    for (var i = 0; i < columnNames.length; i++) {
        var tempFlagD = false;
        for (var j = 0; j < sortcolumnNames.length; j++) {
            var tmpCN = columnNames[i].split(",")[0];
            var tmpSCN = sortcolumnNames[j].split(",")[0];
            if (tmpCN == tmpSCN) {
                sortDeatail[i] = new Array(tmpCN, sortType);
                tempFlagD = true;
                break;
            }
        }
        if (tempFlagD != true) {
            sortDeatail[i] = new Array(tmpCN, "");
        }
    }
}

//创建表头
function CreateGrid() {
    $("#tabInfo").append("<table id='dataInfo' class='blueTable' width='100%'><tr id='gridTitle' class='blueTableTitle'></tr></table>");
    for (var i = 0; i < sortDeatail.length; i++) {
        tmp = sortDeatail[i];
        if (tmp[1] != "") {
            if (tmp[1] == "asc") {
                $("#gridTitle").append("<td><a id='" + columnNames[i].split(",")[1] + "," + columnNames[i].split(",")[0] + "," + sortType + "' onclick='SourtByColumn(this)' href='javascript:void(0);' >" + columnNames[i].split(",")[1] + "↑</a></td>");
            } else {
                $("#gridTitle").append("<td><a id='" + columnNames[i].split(",")[1] + "," + columnNames[i].split(",")[0] + "," + sortType + "' onclick='SourtByColumn(this)' href='javascript:void(0);' >" + columnNames[i].split(",")[1] + "↓</a></td>");
            }
        } else {
            $("#gridTitle").append("<td>" + columnNames[i].split(",")[1] + "</td>");
        }
    }
}

//初始化列数据
function InitData(str) {
    var arr = str.split(",");
    var jsonStr = "[";
    for (var i = 0; i < arr.length; i += 5) {
        jsonStr += "{\"columnName\":\"" + arr[i] + "\",\"display\":\"" + arr[i + 1] + "\",\"isSourt\":\"" + arr[i + 2] + "\",\"Type\":\"" + arr[i + 3] + "\",\"validate\":\"" + arr[i + 4] + "\"},";
    }
    jsonStr = jsonStr.substring(0, jsonStr.length - 1);
    jsonStr += "]";
    var json = eval('(' + jsonStr + ')');
    var temi = 0;
    var temj = 0;
    for (var i = 0; i < json.length; i++) {
        columnNames[temi] = json[i].columnName + "," + json[i].display + "," + json[i].Type + "," + json[i].validate;
        if (json[i].isSourt == "true") {
            sortcolumnNames[temj] = json[i].columnName + "," + json[i].display + "," + json[i].Type + "," + json[i].validate;
            temj++;
        }
        temi++;
    }
}

//初始化操作数据
function InitOpreate(str) {
    var arr = str.split(",");
    var jsonStr = "[";
    for (var i = 0; i < arr.length; i += 3) {
        jsonStr += "{\"opreateName\":\"" + arr[i] + "\",\"Url\":\"" + arr[i + 1] + "\",\"IsRedirect\":\"" + arr[i + 2] + "\"},";
    }
    jsonStr = jsonStr.substring(0, jsonStr.length - 1);
    jsonStr += "]";
    var json = eval('(' + jsonStr + ')');
    for (var i = 0; i < json.length; i++) {
        opreate[i] = json[i].opreateName + "," + json[i].Url + "," + json[i].IsRedirect;
    }
}

//排序
function SourtByColumn(ctr) {
    var content = $(ctr).attr("id");
    var tempContent = content.split(',');
    var propoty = tempContent[1];
    var tempType = tempContent[2];
    for (var i = 0; i < sortDeatail.length; i++) {
        if (sortDeatail[i][0] == propoty) {
            if (sortDeatail[i][1] == "asc") {
                sortDeatail[i][1] = "desc";
                sortType = "desc";
                tempType = "desc";
                break;
            } else {
                sortDeatail[i][1] = "asc";
                sortType = "asc";
                tempType = "asc";
                break;
            }
        }
    }
    BindData(pageNum, tmpSize, "", "", propoty, tempType);
}

//绑定数据
function BindData(pageIndex, pageSize, strSearchProperty, strSearchCondition, strSortProperty, strSortCondition) {
    var tmpCount = 0;
    tmpSize = pageSize;
    $.ajax({
        type: "GET",
        url: urlGetData,
        dataType: "json",
        data: { pageIndex: pageIndex, pageSize: pageSize, strSearchProperty: strSearchProperty, strSearchCondition: strSearchCondition, strSortProperty: strSortProperty, strSortCondition: strSortCondition },
        success: function (json) {
            if (json != null) {
                if (json[json.length - 1].ID == 0) {
                    tmpCount = 1;
                    tempStart = 1;
                } else {
                    tmpCount = json[json.length - 1].ID;
                }
            } else {
                tmpCount = 1;
                tempStart = 1;
            }
            pageNum = pageIndex;
            $("#pageIndex").empty();
            $("#tabInfo").empty();
            CreateGrid();
            var tempStart = pageIndex;
            if (json != null && json.length != 1) {
                if (json.length != 1) {
                    for (var x = 0; x < json.length - 1; x++) {
                        var item = json[x];
                        var appendStr = "<tr>";
                        for (var y = 0; y < columnNames.length - 1; y++) {
                            var pro = columnNames[y].split(",")[0];
                            if (item[pro] == true && item[pro].toString() != "1") {
                                appendStr += "<td><input type='checkbox' checked='checked' disabled='disabled'></td>";
                            } else if (item[pro] == false) {
                                appendStr += "<td><input type='checkbox' disabled='disabled'></td>";
                            } else if (item[pro] != null && item[pro].toString().substring(0, 5) == "/Date") {
                                appendStr += "<td>" + DateFormat(item[pro]) + "</td>";
                            } else {
                                appendStr += "<td>" + item[pro] + "</td>";
                            }
                        }
                        appendStr += "<td>"
                        for (var z = 0; z < opreate.length; z++) {
                            var temd = opreate[z].split(",");
                            var oName = temd[0];
                            var oUrl = temd[1];
                            var oState = temd[2];
                            if (oState == "true") {
                                appendStr += "<a href='" + oUrl + "/" + item['ID'] + "'><img src='../../Scripts/zTree/css/zTreeStyle/img/diy/2.png' alt='' />" + oName + "</a>&nbsp;丨&nbsp;";
                            } else {
                                appendStr += "<img src='../../Content/Images/shape_move_back.png' alt='' /><a href='javascript:void(0);' onclick='CustomFunction(\"" + oUrl + "\"," + item['ID'] + ")'>" + oName + "</a>&nbsp;";
                            }
                        }
                        appendStr += "</td>"
                        appendStr += "</tr>";
                        $("#dataInfo").append(appendStr);
                    }
                }
            } else {
                var tmpColumnNum = columnNames.length;
                $("#dataInfo").append("<tr><td colspan=" + tmpColumnNum + ">没有满足条件的数据！</td></tr>");
            }
            $("#pageIndex").paginate({
                count: tmpCount,
                start: tempStart,
                display: 10,
                border: false,
                text_color: '#79B5E3',
                background_color: 'none',
                text_hover_color: '#2573AF',
                background_hover_color: 'none',
                images: false,
                mouse: 'press',
                onChange: function (page) {
                    if (json != null || json.length != 0) {
                        BindData(page, pageSize, strSearchProperty, strSearchCondition, strSortProperty, strSortCondition);
                    }
                }
            })
        },
        error: function (msg) {
            alert("返回数据时出错！请联系本插件作者！");
        }
    });
}

//转换时间格式

function DateFormat(val) {
    if (val != null) {
        var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        return date.getFullYear() + "-" + month + "-" + currentDate;
    }
    return "";
}

//用户自定义操作
function CustomFunction(url, id) {
    $.ajax({
        url: url,
        type: "POST",
        data: { id: id },
        success: function () {
            alert("操作成功！");
            window.location.reload();
        }
    })
}

//配置验证控件
function ValidateInte() {
    $(function () {
        var xOffset = -20; // x distance from mouse
        var yOffset = 20; // y distance from mouse
        //input action
        $("[reg],[url]:not([reg]),[tip]").hover(
		function (e) {
		    if ($(this).attr('tip') != undefined) {
		        var top = (e.pageY + yOffset);
		        var left = (e.pageX + xOffset);
		        $('body').append('<p id="vtip"><img id="vtipArrow" src="../../Scripts/PageCreater/Images/vtip_arrow.png"/>' + $(this).attr('tip') + '</p>');
		        $('p#vtip').css("top", top + "px").css("left", left + "px");
		        $('p#vtip').bgiframe();
		    }
		},
		function () {
		    if ($(this).attr('tip') != undefined) {
		        $("p#vtip").remove();
		    }
		}
	).mousemove(
		function (e) {
		    if ($(this).attr('tip') != undefined) {
		        var top = (e.pageY + yOffset);
		        var left = (e.pageX + xOffset);
		        $("p#vtip").css("top", top + "px").css("left", left + "px");
		    }
		}
	).blur(function () {
	    if ($(this).attr("url") != undefined) {
	        ajax_validate($(this));
	    } else if ($(this).attr("reg") != undefined) {
	        validate($(this));
	    }
	});
        function validate(obj) {
            var reg = new RegExp(obj.attr("reg"));
            var objValue = obj.attr("value");

            if (!reg.test(objValue)) {
                change_error_style(obj, "add");
                change_tip(obj, null, "remove");
                return false;
            } else {
                if (obj.attr("url") == undefined) {
                    change_error_style(obj, "remove");
                    change_tip(obj, null, "remove");
                    return true;
                } else {
                    return ajax_validate(obj);
                }
            }
        }
    });
}

//PageCreater End

//Paginate Begin 此处再次封装Paginate翻页控件

(function ($) {
    $.fn.paginate = function (options) {
        var opts = $.extend({}, $.fn.paginate.defaults, options);
        return this.each(function () {
            $this = $(this);
            var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
            var selectedpage = o.start;
            $.fn.draw(o, $this, selectedpage);
        });
    };
    var outsidewidth_tmp = 0;
    var insidewidth = 0;
    var bName = navigator.appName;
    var bVer = navigator.appVersion;
    if (bVer.indexOf('MSIE 7.0') > 0)
        var ver = "ie7";
    $.fn.paginate.defaults = {
        count: 5,
        start: 12,
        display: 5,
        border: true,
        border_color: '#fff',
        text_color: '#8cc59d',
        background_color: 'black',
        border_hover_color: '#fff',
        text_hover_color: '#fff',
        background_hover_color: '#fff',
        rotate: true,
        images: true,
        mouse: 'slide',
        onChange: function () { return false; }
    };
    $.fn.draw = function (o, obj, selectedpage) {
        if (o.display > o.count)
            o.display = o.count;
        $this.empty();
        if (o.images) {
            var spreviousclass = 'jPag-sprevious-img';
            var previousclass = 'jPag-previous-img';
            var snextclass = 'jPag-snext-img';
            var nextclass = 'jPag-next-img';
        }
        else {
            var spreviousclass = 'jPag-sprevious';
            var previousclass = 'jPag-previous';
            var snextclass = 'jPag-snext';
            var nextclass = 'jPag-next';
        }
        var _first = $(document.createElement('a')).addClass('jPag-first').html('First');

        if (o.rotate) {
            if (o.images) var _rotleft = $(document.createElement('span')).addClass(spreviousclass);
            else var _rotleft = $(document.createElement('span')).addClass(spreviousclass).html('&laquo;');
        }

        var _divwrapleft = $(document.createElement('div')).addClass('jPag-control-back');
        _divwrapleft.append(_first).append(_rotleft);

        var _ulwrapdiv = $(document.createElement('div')).css('overflow', 'hidden');
        var _ul = $(document.createElement('ul')).addClass('jPag-pages')
        var c = (o.display - 1) / 2;
        var first = selectedpage - c;
        var selobj;
        for (var i = 0; i < o.count; i++) {
            var val = i + 1;
            if (val == selectedpage) {
                var _obj = $(document.createElement('li')).html('<span class="jPag-current">' + val + '</span>');
                selobj = _obj;
                _ul.append(_obj);
            }
            else {
                var _obj = $(document.createElement('li')).html('<a>' + val + '</a>');
                _ul.append(_obj);
            }
        }
        _ulwrapdiv.append(_ul);

        if (o.rotate) {
            if (o.images) var _rotright = $(document.createElement('span')).addClass(snextclass);
            else var _rotright = $(document.createElement('span')).addClass(snextclass).html('&raquo;');
        }

        var _last = $(document.createElement('a')).addClass('jPag-last').html('Last');
        var _divwrapright = $(document.createElement('div')).addClass('jPag-control-front');
        _divwrapright.append(_rotright).append(_last);

        //append all:
        $this.addClass('jPaginate').append(_divwrapleft).append(_ulwrapdiv).append(_divwrapright);

        if (!o.border) {
            if (o.background_color == 'none') var a_css = { 'color': o.text_color };
            else var a_css = { 'color': o.text_color, 'background-color': o.background_color };
            if (o.background_hover_color == 'none') var hover_css = { 'color': o.text_hover_color };
            else var hover_css = { 'color': o.text_hover_color, 'background-color': o.background_hover_color };
        }
        else {
            if (o.background_color == 'none') var a_css = { 'color': o.text_color, 'border': '1px solid ' + o.border_color };
            else var a_css = { 'color': o.text_color, 'background-color': o.background_color, 'border': '1px solid ' + o.border_color };
            if (o.background_hover_color == 'none') var hover_css = { 'color': o.text_hover_color, 'border': '1px solid ' + o.border_hover_color };
            else var hover_css = { 'color': o.text_hover_color, 'background-color': o.background_hover_color, 'border': '1px solid ' + o.border_hover_color };
        }

        $.fn.applystyle(o, $this, a_css, hover_css, _first, _ul, _ulwrapdiv, _divwrapright);
        //calculate width of the ones displayed:
        var outsidewidth = outsidewidth_tmp - _first.parent().width() - 3;
        if (ver == 'ie7') {
            _ulwrapdiv.css('width', outsidewidth + 72 + 'px');
            _divwrapright.css('left', outsidewidth_tmp + 6 + 72 + 'px');
        }
        else {
            _ulwrapdiv.css('width', outsidewidth + 'px');
            _divwrapright.css('left', outsidewidth_tmp + 6 + 'px');
        }

        if (o.rotate) {
            _rotright.hover(
				function () {
				    thumbs_scroll_interval = setInterval(
					function () {
					    var left = _ulwrapdiv.scrollLeft() + 1;
					    _ulwrapdiv.scrollLeft(left);
					},
					20
				  );
				},
				function () {
				    clearInterval(thumbs_scroll_interval);
				}
			);
            _rotleft.hover(
				function () {
				    thumbs_scroll_interval = setInterval(
					function () {
					    var left = _ulwrapdiv.scrollLeft() - 1;
					    _ulwrapdiv.scrollLeft(left);
					},
					20
				  );
				},
				function () {
				    clearInterval(thumbs_scroll_interval);
				}
			);
            if (o.mouse == 'press') {
                _rotright.mousedown(
					function () {
					    thumbs_mouse_interval = setInterval(
						function () {
						    var left = _ulwrapdiv.scrollLeft() + 5;
						    _ulwrapdiv.scrollLeft(left);
						},
						20
					  );
					}
				).mouseup(
					function () {
					    clearInterval(thumbs_mouse_interval);
					}
				);
                _rotleft.mousedown(
					function () {
					    thumbs_mouse_interval = setInterval(
						function () {
						    var left = _ulwrapdiv.scrollLeft() - 5;
						    _ulwrapdiv.scrollLeft(left);
						},
						20
					  );
					}
				).mouseup(
					function () {
					    clearInterval(thumbs_mouse_interval);
					}
				);
            }
            else {
                _rotleft.click(function (e) {
                    var width = outsidewidth - 10;
                    var left = _ulwrapdiv.scrollLeft() - width;
                    _ulwrapdiv.animate({ scrollLeft: left + 'px' });
                });

                _rotright.click(function (e) {
                    var width = outsidewidth - 10;
                    var left = _ulwrapdiv.scrollLeft() + width;
                    _ulwrapdiv.animate({ scrollLeft: left + 'px' });
                });
            }
        }

        //first and last:
        _first.click(function (e) {
            _ulwrapdiv.animate({ scrollLeft: '0px' });
            _ulwrapdiv.find('li').eq(0).click();
        });
        _last.click(function (e) {
            _ulwrapdiv.animate({ scrollLeft: insidewidth + 'px' });
            _ulwrapdiv.find('li').eq(o.count - 1).click();
        });

        //click a page
        _ulwrapdiv.find('li').click(function (e) {
            selobj.html('<a>' + selobj.find('.jPag-current').html() + '</a>');
            var currval = $(this).find('a').html();
            $(this).html('<span class="jPag-current">' + currval + '</span>');
            selobj = $(this);
            $.fn.applystyle(o, $(this).parent().parent().parent(), a_css, hover_css, _first, _ul, _ulwrapdiv, _divwrapright);
            var left = (this.offsetLeft) / 2;
            var left2 = _ulwrapdiv.scrollLeft() + left;
            var tmp = left - (outsidewidth / 2);
            if (ver == 'ie7')
                _ulwrapdiv.animate({ scrollLeft: left + tmp - _first.parent().width() + 52 + 'px' });
            else
                _ulwrapdiv.animate({ scrollLeft: left + tmp - _first.parent().width() + 'px' });
            o.onChange(currval);
        });

        var last = _ulwrapdiv.find('li').eq(o.start - 1);
        last.attr('id', 'tmp');
        var left = document.getElementById('tmp').offsetLeft / 2;
        last.removeAttr('id');
        var tmp = left - (outsidewidth / 2);
        if (ver == 'ie7') _ulwrapdiv.animate({ scrollLeft: left + tmp - _first.parent().width() + 52 + 'px' });
        else _ulwrapdiv.animate({ scrollLeft: left + tmp - _first.parent().width() + 'px' });
    }

    $.fn.applystyle = function (o, obj, a_css, hover_css, _first, _ul, _ulwrapdiv, _divwrapright) {
        obj.find('a').css(a_css);
        obj.find('span.jPag-current').css(hover_css);
        obj.find('a').hover(
					function () {
					    $(this).css(hover_css);
					},
					function () {
					    $(this).css(a_css);
					}
					);
        obj.css('padding-left', _first.parent().width() + 5 + 'px');
        insidewidth = 0;

        obj.find('li').each(function (i, n) {
            if (i == (o.display - 1)) {
                outsidewidth_tmp = this.offsetLeft + this.offsetWidth;
            }
            insidewidth += this.offsetWidth;
        })
        _ul.css('width', insidewidth + 'px');
    }
})(jQuery);

//Paginate End

//EasyValidator Begin 此处再次封装和修改EasyValidator控件

$(function () {
    var xOffset = -20; // x distance from mouse
    var yOffset = 20; // y distance from mouse  


    //input action
    $("[reg],[url]:not([reg]),[tip]").hover(
		function (e) {
		    if ($(this).attr('tip') != undefined) {
		        var top = (e.pageY + yOffset);
		        var left = (e.pageX + xOffset);
		        $('body').append('<p id="vtip"><img id="vtipArrow" src="../../Scripts/PageCreater/Images/vtip_arrow.png"/>' + $(this).attr('tip') + '</p>');
		        $('p#vtip').css("top", top + "px").css("left", left + "px");
		        $('p#vtip').bgiframe();
		    }
		},
		function () {
		    if ($(this).attr('tip') != undefined) {
		        $("p#vtip").remove();
		    }
		}
	).mousemove(
		function (e) {
		    if ($(this).attr('tip') != undefined) {
		        var top = (e.pageY + yOffset);
		        var left = (e.pageX + xOffset);
		        $("p#vtip").css("top", top + "px").css("left", left + "px");
		    }
		}
	).blur(function () {
	    if ($(this).attr("url") != undefined) {
	        ajax_validate($(this));
	    } else if ($(this).attr("reg") != undefined) {
	        validate($(this));
	    }
	});

    $("form").submit(function () {
        var isSubmit = true;
        $(this).find("[reg],[url]:not([reg])").each(function () {
            if ($(this).attr("reg") == undefined) {
                if (!ajax_validate($(this))) {
                    isSubmit = false;
                }
            } else {
                if (!validate($(this))) {
                    isSubmit = false;
                }
            }
        });
        if (typeof (isExtendsValidate) != "undefined") {
            if (isSubmit && isExtendsValidate) {
                return extendsValidate();
            }
        }
        if (isSubmit == false) {
            alert("验证失败，请查看页面提示！");
        }
        return isSubmit;
    });

});

function validate(obj) {
    var reg = new RegExp(obj.attr("reg"));
    var objValue = obj.attr("value");

    if (!reg.test(objValue)) {
        change_error_style(obj, "add");
        change_tip(obj, null, "remove");
        return false;
    } else {
        if (obj.attr("url") == undefined) {
            change_error_style(obj, "remove");
            change_tip(obj, null, "remove");
            return true;
        } else {
            return ajax_validate(obj);
        }
    }
}

function ajax_validate(obj) {

    var url_str = obj.attr("url");
    if (url_str.indexOf("?") != -1) {
        url_str = url_str + "&" + obj.attr("name") + "=" + obj.attr("value");
    } else {
        url_str = url_str + "?" + obj.attr("name") + "=" + obj.attr("value");
    }
    var feed_back = $.ajax({ url: url_str, cache: false, async: false }).responseText;
    feed_back = feed_back.replace(/(^\s*)|(\s*$)/g, "");
    if (feed_back == 'success') {
        change_error_style(obj, "remove");
        change_tip(obj, null, "remove");
        return true;
    } else {
        change_error_style(obj, "add");
        change_tip(obj, feed_back, "add");
        return false;
    }
}

function change_tip(obj, msg, action_type) {

    if (obj.attr("tip") == undefined) {//初始化判断TIP是否为空
        obj.attr("is_tip_null", "yes");
    }
    if (action_type == "add") {
        if (obj.attr("is_tip_null") == "yes") {
            obj.attr("tip", msg);
        } else {
            if (msg != null) {
                if (obj.attr("tip_bak") == undefined) {
                    obj.attr("tip_bak", obj.attr("tip"));
                }
                obj.attr("tip", msg);
            }
        }
    } else {
        if (obj.attr("is_tip_null") == "yes") {
            obj.removeAttr("tip");
            obj.removeAttr("tip_bak");
        } else {
            obj.attr("tip", obj.attr("tip_bak"));
            obj.removeAttr("tip_bak");
        }
    }
}

function change_error_style(obj, action_type) {
    if (action_type == "add") {
        obj.addClass("input_validation-failed");
    } else {
        obj.removeClass("input_validation-failed");
    }
}

$.fn.validate_callback = function (msg, action_type, options) {
    this.each(function () {
        if (action_type == "failed") {
            change_error_style($(this), "add");
            change_tip($(this), msg, "add");
        } else {
            change_error_style($(this), "remove");
            change_tip($(this), null, "remove");
            change_succse_style($(this), "add")
        }
    });
};

//EasyValidator End